package com.childenglish.controller;

import com.childenglish.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/learning")
public class LearningController {

    @RequiresPermissions("learning:listening:view")
    @GetMapping("/listening")
    public R getListeningMaterials() {
        Map<String, Object> data = new HashMap<>();
        data.put("materials", new String[]{
                "儿童英语儿歌合集",
                "基础单词发音练习",
                "日常对话听力训练"
        });
        data.put("recommended", "儿童英语儿歌合集");
        return R.ok("获取磨耳朵材料成功").data(data);
    }

    @RequiresPermissions("learning:reading:view")
    @PostMapping("/reading/start")
    public R startReading(@RequestBody Map<String, Object> request) {
        String bookName = (String) request.get("bookName");
        Map<String, Object> data = new HashMap<>();
        data.put("sessionId", "READ_" + System.currentTimeMillis());
        data.put("book", bookName);
        data.put("status", "reading");
        data.put("progress", 0);

        return R.ok("开始绘本阅读").data(data);
    }

    @RequiresPermissions("learning:game:view")
    @GetMapping("/game/levels")
    public R getGameLevels() {
        Map<String, Object> data = new HashMap<>();

        // 修正：使用HashMap代替Map.of
        Map<String, Object> level1 = new HashMap<>();
        level1.put("level", 1);
        level1.put("name", "字母认知");
        level1.put("completed", true);
        level1.put("stars", 3);

        Map<String, Object> level2 = new HashMap<>();
        level2.put("level", 2);
        level2.put("name", "单词配对");
        level2.put("completed", true);
        level2.put("stars", 2);

        Map<String, Object> level3 = new HashMap<>();
        level3.put("level", 3);
        level3.put("name", "句子构造");
        level3.put("completed", false);
        level3.put("stars", 0);

        data.put("levels", new Object[]{level1, level2, level3});
        return R.ok("获取游戏关卡成功").data(data);
    }
}